package com.eelye.util;

import java.math.BigDecimal;

public class StringUtil {

    /**
     * 转化成整数。把带有小数点的字符串，乘以multiplier后，返回整数
     *
     * @param str
     * @param multiplier
     * @return
     */
    public static int toInt(String str, int multiplier) {
        BigDecimal b = new BigDecimal(str);
        BigDecimal ret = b.multiply(new BigDecimal(multiplier));

        return ret.intValue();
    }

    /**
     * 转化成整数。把带有小数点的字符串，乘以multiplier后，返回整数
     *
     * @param str
     * @param multiplier
     * @return
     */
    static public long toLong(String str, int multiplier) {
        BigDecimal b = new BigDecimal(str);
        BigDecimal ret = b.multiply(new BigDecimal(multiplier));

        return ret.longValue();
    }

    public static String ReplaceWithArray(String search[], String replace[], String subject) {
        String ret = subject;
        for (int i = 0; i < search.length; ++i) {
            ret = ret.replace(search[i], replace[i]);
        }

        return ret;
    }

    public static boolean isBlank(String str) {
        final int strLen = str == null ? 0 : str.length();
        if (strLen == 0) {
            return true;
        }
        for (int i = 0; i < strLen; i++) {
            if (!Character.isWhitespace(str.charAt(i))) {
                return false;
            }
        }
        return true;
    }


}
